package com.atguigu03.threadsafe.threadsafe;



class SaleTickets1 extends Thread {

    static int tickets = 100;
    private static boolean flag = true;

    @Override
    public void run() {
        while (flag) {
            show();
        }

    }

    private static synchronized void show() {
        if(tickets > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + ":" + tickets);
            tickets--;
        } else {
            flag = false;
        }
    }
}

public class TicketsTest1 {
    public static void main(String[] args) {
        SaleTickets1 t1 = new SaleTickets1();
        SaleTickets1 t2 = new SaleTickets1();
        SaleTickets1 t3 = new SaleTickets1();

        t1.start();
        t2.start();
        t3.start();
    }
}
